/**
 * 操作底图.
 */

String.prototype.endWith = function(str){
     if(str==null || str=="" || this.length == 0 ||str.length > this.length){   
       return false;
     }
     //alert("THIS:" + this +",SUB:" + this.substring(this.length- 1, this.length));
     if(this.substring(this.length- 1, this.length) == str){
         return true;
     }else{
         return false;
     }
     return false;
};

 function SPLITJING(strs){
    var keys = strs.split('>#');
    if(keys[0] != undefined && keys[1] != undefined){
        return keys[0] + "=" + $('#' + keys[1]).val() + "&";
    }
    return "";
 }

function jumptohref(targetelm){
    var href = $(targetelm).attr('href');
    if(href == undefined){
    	return true;
    }
	if(href.substr(0,1) == '#'){
		return true;
	}
    var dataparms = $(targetelm).attr('data-pars');
    var dataidprams = $(targetelm).attr('data-id-pars');

    var stridpara = "";
    if(dataidprams != undefined ){
        if(dataidprams.length > 1){
            if(dataidprams.indexOf(',') > 0){ // 有逗号
                dataidprams.replace(' ', '');
                var comkeys = dataidprams.split(',');
                for (var i = 0; i < comkeys.length; i ++) {
                    stridpara += SPLITJING(comkeys[i]);
                }

            }else{// 无逗号，只有一个.
                stridpara = SPLITJING(dataidprams);
            }
        }
        if(stridpara.endWith('&')){
           // alert('&结尾!~');
           stridpara = stridpara.substring(0, stridpara.length - 1);
        // }else{
        //     alert('无&结尾!~');
        }

    }
    if (dataparms != undefined && dataparms.length > 0) {
        href = href + "?" + dataparms;
        if(stridpara != undefined && stridpara.length > 0)
            href = href + "&" + stridpara
    }else{
        if(stridpara != undefined && stridpara.length > 0)
        href = href + "?" + stridpara;
    }
    if(href != undefined)
        window.location.href = href;
}

 $(function(){
    //alert('loaded!~');
    mui('body').on('tap', '.hoyinav', function(){
        //alert('taps');
        var a = this, parent;
        jumptohref(a);
    });

    mui('body').on('tap', 'a', function(){
        //alert('taps');
        var a = this, parent;
        jumptohref(a);
    });

    mui('body').on('tap', '.jumpbtn', function(){
        var jumpbtn = this, parent;
        jumptohref(jumpbtn);
    })
 });

 function ActiveNav(id){
     $('.hoyinav').each(function(idx, item){
        $(item).removeClass('mui-active');
     });
     $(id).addClass('mui-active');
 }


 function SetNavTitle(title){
     $('#header_title').html(title);
 }